package geektime.spring.springbucks.controller;

import geektime.spring.springbucks.model.Coffee;
import geektime.spring.springbucks.service.CoffeeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/coffee")
@Slf4j
public class CoffeeController {
    @Autowired
    private CoffeeService coffeeService;


    @RequestMapping(path = "/getJson/{id}", method = RequestMethod.GET
            , produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Coffee getById(@PathVariable Long id) {
        Coffee coffee = coffeeService.findById(id);
        log.info("Coffee {}:", coffee);
        return coffee;
    }

    @RequestMapping(path = "/getXml/{id}", method = RequestMethod.GET
            , produces = MediaType.APPLICATION_XML_VALUE)
    @ResponseBody
    public Coffee getByIdXml(@PathVariable Long id) {
        Coffee coffee = coffeeService.findById(id);
        log.info("Coffee {}:", coffee);
        return coffee;
    }

}
